home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 176-200 / disk_190 / nethack / twee.zoo / prisym.c < prev    next >
C/C++ Source or Header  |  1988-07-24  |  8KB  |  383 lines

  1. /*    SCCS Id: @(#)prisym.c   2.3     88/03/29
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3.  
  4. #include <stdio.h>
  5. #include "hack.h"
  6.  
  7. extern xchar scrlx, scrhx, scrly, scrhy; /* corners from pri.c */
  8.  
  9. atl(x,y,ch)
  10. register x,y;
  11. {
  12.     register struct rm *crm = &levl[x][y];
  13.  
  14.     if(x<0 || x>COLNO-1 || y<0 || y>ROWNO-1){
  15.         impossible("atl(%d,%d,%c)",x,y,ch);
  16.         return;
  17.     }
  18.     if(RM_SEEN(*crm) && crm->scrsym == ch) return;
  19.     crm->scrsym = ch;
  20.     RM_SET_NEW(*crm);
  21.     on_scr(x,y);
  22. }
  23.  
  24. on_scr(x,y)
  25. register x,y;
  26. {
  27.     if(x < scrlx) scrlx = x;
  28.     if(x > scrhx) scrhx = x;
  29.     if(y < scrly) scrly = y;
  30.     if(y > scrhy) scrhy = y;
  31. }
  32.  
  33. /* call: (x,y) - display
  34.     (-1,0) - close (leave last symbol)
  35.     (-1,-1)- close (undo last symbol)
  36.     (-1,let)-open: initialize symbol
  37.     (-2,let)-change let
  38. */
  39.  
  40. tmp_at(x,y) int x,y; {
  41. static schar prevx, prevy;
  42. static char let;
  43.     if((int)x == -2){       /* change let call */
  44.         let = y;
  45.         return;
  46.     }
  47.     if((int)x == -1 && (int)y >= 0){        /* open or close call */
  48.         let = y;
  49.         prevx = -1;
  50.         return;
  51.     }
  52.     if(prevx >= 0 && cansee(prevx,prevy)) {
  53.         delay_output();
  54.         prl(prevx, prevy);      /* in case there was a monster */
  55.         at(prevx, prevy, levl[prevx][prevy].scrsym);
  56.     }
  57.     if(x >= 0){     /* normal call */
  58.         if(cansee(x,y)) at(x,y,let);
  59.         prevx = x;
  60.         prevy = y;
  61.     } else {    /* close call */
  62.         let = 0;
  63.         prevx = -1;
  64.     }
  65. }
  66.  
  67. /* like the previous, but the symbols are first erased on completion */
  68. Tmp_at(x,y) int x,y; {
  69. static char let;
  70. static xchar cnt;
  71. static coord tc[COLNO];     /* but watch reflecting beams! */
  72. register xx,yy;
  73.     if((int)x == -1) {
  74.         if(y > 0) {     /* open call */
  75.             let = y;
  76.             cnt = 0;
  77.             return;
  78.         }
  79.         /* close call (do not distinguish y==0 and y==-1) */
  80.         while(cnt--) {
  81.             xx = tc[cnt].x;
  82.             yy = tc[cnt].y;
  83.             prl(xx, yy);
  84.             at(xx, yy, levl[xx][yy].scrsym);
  85.         }
  86.         cnt = let = 0;    /* superfluous */
  87.         return;
  88.     }
  89.     if((int)x == -2) {      /* change let call */
  90.         let = y;
  91.         return;
  92.     }
  93.     /* normal call */
  94.     if(cansee(x,y)) {
  95.         if(cnt) delay_output();
  96.         at(x,y,let);
  97.         tc[cnt].x = x;
  98.         tc[cnt].y = y;
  99.         if(++cnt >= COLNO) panic("Tmp_at overflow?");
  100.         RM_CLR_NEW(levl[x][y]); /* prevent pline-nscr erasing --- */
  101.     }
  102. }
  103.  
  104. curs_on_u(){
  105.     curs(u.ux, u.uy+2);
  106. }
  107.  
  108. pru()
  109. {
  110.     if(u.udispl && (Invisible || u.udisx != u.ux || u.udisy != u.uy))
  111.         /* if(! RM_NEW(levl[u.udisx][u.udisy])) */
  112.             if(!vism_at(u.udisx, u.udisy))
  113.                 newsym(u.udisx, u.udisy);
  114.     if(Invisible) {
  115.         u.udispl = 0;
  116.         prl(u.ux,u.uy);
  117.     } else
  118.     if(!u.udispl || u.udisx != u.ux || u.udisy != u.uy) {
  119.         atl(u.ux, u.uy, u.usym);
  120.         u.udispl = 1;
  121.         u.udisx = u.ux;
  122.         u.udisy = u.uy;
  123.     }
  124.     RM_SET_SEEN(levl[u.ux][u.uy]);
  125. }
  126.  
  127. #ifndef NOWORM
  128. #include    "wseg.h"
  129. extern struct wseg *m_atseg;
  130. #endif
  131.  
  132. /* print a position that is visible for @ */
  133. prl(x,y)
  134. {
  135.     register struct rm *room;
  136.     register struct monst *mtmp;
  137.     register struct obj *otmp;
  138.     register struct trap *ttmp;
  139.  
  140.     if(x == u.ux && y == u.uy && (!Invisible)) {
  141.         pru();
  142.         return;
  143.     }
  144.     if(!isok(x,y)) return;
  145.     room = &levl[x][y];
  146.     if((!RM_TYP(*room)) ||
  147.        (IS_ROCK(RM_TYP(*room)) && RM_TYP(levl[u.ux][u.uy]) == CORR))
  148.         return;
  149.     if((mtmp = m_at(x,y)) && !mtmp->mhide &&
  150.         (!mtmp->minvis || See_invisible)) {
  151. #ifndef NOWORM
  152.         if(m_atseg)
  153.             pwseg(m_atseg);
  154.         else
  155. #endif
  156.         pmon(mtmp);
  157.     }
  158.     else if((otmp = o_at(x,y)) && RM_TYP(*room) != POOL)
  159.         atl(x,y,Hallucination ? rndobjsym() : otmp->olet);
  160. #ifdef SPIDERS
  161.     else if((!mtmp || mtmp->data == PM_SPIDER) &&
  162.           (ttmp = t_at(x,y)) && ttmp->ttyp == WEB)
  163.         atl(x,y,WEB_SYM);
  164. #endif
  165.     else if(mtmp && (!mtmp->minvis || See_invisible)) {
  166.         /* must be a hiding monster, but not hiding right now */
  167.         /* assume for the moment that long worms do not hide */
  168.         pmon(mtmp);
  169.     }
  170.     else if(g_at(x,y) && RM_TYP(*room) != POOL)
  171.         atl(x,y,Hallucination ? rndobjsym() : GOLD_SYM);
  172.     else if(!RM_SEEN(*room) || room->scrsym == STONE_SYM) {
  173.         /* room->new = room->seen = 1; */
  174.         RM_SET_NEW(*room);
  175.         RM_SET_SEEN(*room);
  176.         newsym(x,y);
  177.         on_scr(x,y);
  178.     }
  179.     RM_SET_SEEN(*room);
  180. }
  181.  
  182. char
  183. news0(x,y)
  184. register xchar x,y;
  185. {
  186.     register struct obj *otmp;
  187.     register struct trap *ttmp;
  188.     struct rm *room;
  189.     register unsigned char tmp; /* OIS: don't compare char with uchar */
  190.  
  191.     room = &levl[x][y];
  192.     if(!RM_SEEN(*room)) tmp = STONE_SYM;
  193.     else if (RM_TYP(*room) == POOL) tmp = POOL_SYM;
  194.     else if(!Blind && (otmp = o_at(x,y)))
  195.         tmp = Hallucination ? rndobjsym() : otmp->olet;
  196.     else if(!Blind && g_at(x,y))
  197.         tmp = Hallucination ? rndobjsym() : GOLD_SYM;
  198.     else if(x == xupstair && y == yupstair) tmp = UP_SYM;
  199.     else if(x == xdnstair && y == ydnstair) tmp = DN_SYM;
  200. #ifdef SPIDERS
  201.     else if((ttmp = t_at(x,y)) && ttmp->ttyp == WEB) tmp = WEB_SYM;
  202.     else if(ttmp && ttmp->tseen) tmp = TRAP_SYM;
  203. #else
  204.     else if((ttmp = t_at(x,y)) && ttmp->tseen) tmp = TRAP_SYM;
  205. #endif
  206.     else switch (RM_TYP(*room)) {
  207.     case SCORR:
  208.     case SDOOR:
  209.         tmp = room->scrsym;    /* %% wrong after killing mimic ! */
  210.         break;
  211.     case HWALL:
  212.         tmp = room->scrsym;    /* OK for corners only */
  213.         if (!IS_CORNER(tmp))
  214.             tmp = HWALL_SYM;
  215.         break;
  216.     case VWALL:
  217.         tmp = VWALL_SYM;
  218.         break;
  219.     case LDOOR:
  220.     case DOOR:
  221.         tmp = DOOR_SYM;
  222.         break;
  223.     case CORR:
  224.         tmp = CORR_SYM;
  225.         break;
  226.     case ROOM:
  227.         if(RM_LIT(*room) || cansee(x,y) || Blind) tmp = ROOM_SYM;
  228.         else tmp = STONE_SYM;
  229.         break;
  230. #ifdef FOUNTAINS
  231.     case FOUNTAIN:
  232.         tmp = FOUNTAIN_SYM;
  233.         break;
  234. #endif
  235. #ifdef NEWCLASS
  236.     case THRONE:
  237.         tmp = THRONE_SYM;
  238.         break;
  239. #endif
  240. #ifdef SINKS
  241.     case SINK:
  242.         tmp = SINK_SYM;
  243.         break;
  244. #endif
  245. /*
  246.     case POOL:
  247.         tmp = POOL_SYM;
  248.         break;
  249. */
  250.     default:
  251.         tmp = ERRCHAR;
  252.     }
  253.     return(tmp);
  254. }
  255.  
  256. newsym(x,y)
  257. register x,y;
  258. {
  259.     atl(x,y,news0(x,y));
  260. }
  261.  
  262. /* used with wand of digging (or pick-axe): fill scrsym and force display */
  263. /* also when a POOL evaporates */
  264. mnewsym(x,y)
  265. register x,y;
  266. {
  267.     register struct rm *room;
  268.     unsigned char newscrsym;    /* OIS */
  269.  
  270.     if(!vism_at(x,y)) {
  271.         room = &levl[x][y];
  272.         newscrsym = news0(x,y);
  273.         if(room->scrsym != newscrsym) {
  274.             room->scrsym = newscrsym;
  275.             RM_CLR_SEEN(*room);
  276.         }
  277.     }
  278. }
  279.  
  280. nosee(x,y)
  281. register x,y;
  282. {
  283.     register struct rm *room;
  284.  
  285.     if(!isok(x,y)) return;
  286.     room = &levl[x][y];
  287.     if(room->scrsym == ROOM_SYM && !RM_LIT(*room) && !Blind) {
  288.         room->scrsym = STONE_SYM;    /* OIS, was ' ' */
  289.         /* Otherwise a STONE_SYM != 32 looks so stupid */
  290.         RM_SET_NEW(*room);
  291.         on_scr(x,y);
  292.     }
  293. }
  294.  
  295. #ifndef QUEST
  296. prl1(x,y)
  297. register x,y;
  298. {
  299.     if(u.dx) {
  300.         if(u.dy) {
  301.             prl(x-(2*u.dx),y);
  302.             prl(x-u.dx,y);
  303.             prl(x,y);
  304.             prl(x,y-u.dy);
  305.             prl(x,y-(2*u.dy));
  306.         } else {
  307.             prl(x,y-1);
  308.             prl(x,y);
  309.             prl(x,y+1);
  310.         }
  311.     } else {
  312.         prl(x-1,y);
  313.         prl(x,y);
  314.         prl(x+1,y);
  315.     }
  316. }
  317.  
  318. nose1(x,y)
  319. register x,y;
  320. {
  321.     if(u.dx) {
  322.         if(u.dy) {
  323.             nosee(x,u.uy);
  324.             nosee(x,u.uy-u.dy);
  325.             nosee(x,y);
  326.             nosee(u.ux-u.dx,y);
  327.             nosee(u.ux,y);
  328.         } else {
  329.             nosee(x,y-1);
  330.             nosee(x,y);
  331.             nosee(x,y+1);
  332.         }
  333.     } else {
  334.         nosee(x-1,y);
  335.         nosee(x,y);
  336.         nosee(x+1,y);
  337.     }
  338. }
  339. #endif /* QUEST /**/
  340.  
  341. vism_at(x,y)
  342. register x,y;
  343. {
  344.     register struct monst *mtmp;
  345.  
  346.     if(x == u.ux && y == u.uy && !Invisible) return(1);
  347.  
  348.     if(mtmp = m_at(x,y)) return((Blind && Telepat) || canseemon(mtmp));
  349.  
  350.     return(0);
  351. }
  352.  
  353. #ifdef NEWSCR
  354. pobj(obj) register struct obj *obj; {
  355. register int show = (!obj->oinvis || See_invisible) &&
  356.         cansee(obj->ox,obj->oy);
  357.     if(obj->odispl){
  358.         if(obj->odx != obj->ox || obj->ody != obj->oy || !show)
  359.         if(!vism_at(obj->odx,obj->ody)){
  360.             newsym(obj->odx, obj->ody);
  361.             obj->odispl = 0;
  362.         }
  363.     }
  364.     if(show && !vism_at(obj->ox,obj->oy)){
  365.         atl(obj->ox,obj->oy,obj->olet);
  366.         obj->odispl = 1;
  367.         obj->odx = obj->ox;
  368.         obj->ody = obj->oy;
  369.     }
  370. }
  371. #endif /* NEWSCR /**/
  372.  
  373. unpobj(obj) register struct obj *obj; {
  374. /*    if(obj->odispl){
  375.         if(!vism_at(obj->odx, obj->ody))
  376.             newsym(obj->odx, obj->ody);
  377.         obj->odispl = 0;
  378.     }
  379. */
  380.     if(!vism_at(obj->ox,obj->oy))
  381.         newsym(obj->ox,obj->oy);
  382. }
  383.